## Ballot Design Incumbency Advantage Experiment
## Justin de Benedictis-Kessner
## Pre-registered experiment 11/3/16 at https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/MQV10L
## Data collected 11/4/16

rm(list=ls())
library(foreign)
library(car)
library(descr)
library(xtable)

a <- read.csv("Incumbency_and_Ballot_Design.csv",stringsAsFactors=F)[-1,]

## Check that randomization worked:
table(a$ballotcondition)

## Recodes:
a[a==""] <- NA # get rid of blanks

# combined incumbent preference from both ballot conditions:
a$mayor_inc_comb <- ifelse(!is.na(a$mayor_off),ifelse(a$mayor_off=="2",1,0),ifelse(a$mayor_on=="2",1,0))
a$council_inc_comb <- ifelse(!is.na(a$Q7),ifelse(a$Q7=="3",1,0),ifelse(a$Q11=="3",1,0))
a$school_inc_comb <- NA
for(i in 1:nrow(a)){
  if((!is.na(a$Q8_1[i]) | !is.na(a$Q8_2[i]) | !is.na(a$Q8_3[i]) | !is.na(a$Q8_4[i]) | !is.na(a$Q8_5[i]) | !is.na(a$Q8_6[i]) | !is.na(a$Q8_7[i]) | !is.na(a$Q8_8[i]) | !is.na(a$Q8_9[i]))){
    a$school_inc_comb[i] <- sum((a$Q8_4[i]=="1" & a$Q8_5[i]=="1" & a$Q8_6[i]=="1"),na.rm=T)
  } else{
    a$school_inc_comb[i] <- sum((a$Q12_4[i]=="1" & a$Q12_5[i]=="1" & a$Q12_6[i]=="1"),na.rm=T)
  }
}
a$health_inc_comb <- ifelse(!is.na(a$Q10),ifelse(a$Q10=="3",1,0),ifelse(a$Q14=="3",1,0))

a$inc_pref_index <- a$mayor_inc_comb + a$council_inc_comb + a$school_inc_comb + a$health_inc_comb

# irrigation district preference (civil engineer==1, retired==2, businessman==3):
a$irrigation_eng_comb <- ifelse(!is.na(a$Q13),ifelse(a$Q13=="1",1,0),ifelse(a$Q9=="1",1,0))

# additive political knowledge index
a$polinfo <- ((a$polinfo1==3) + (a$polinfo2==1) + (a$polinfo3==1) + (a$polinfo4==3) + (a$polinfo5==3))/5

a$scr_pass <- ((a$scr1_12_TEXT=="k") + (a$scr2_1==1)/2 + (a$scr2_6==3)/2)




## Analysis:
# Mayoral incumbency preference by experimental condition:
crosstab(a$mayor_inc_comb,a$ballotcondition,prop.c=T)
summary(lm(mayor_inc_comb ~ ballotcondition, data=a[a$scr_pass==2,])) # beta=0.06, p=0.221

# Council incumbent preference:
summary(lm(council_inc_comb ~ ballotcondition, data=a)) # beta=0.15, p=0.002

# School incumbent preference:
summary(lm(school_inc_comb ~ ballotcondition, data=a)) # beta=0.05, p=0.214

# Health incumbent preference:
summary(lm(health_inc_comb ~ ballotcondition, data=a)) # beta=0.06, p=0.202

# Overall incumbency preference by experimental condition:
crosstab(a$inc_pref_index,a$ballotcondition,prop.c=T)
print.xtable(table(a$inc_pref_index,a$ballotcondition)/sum(table(a$inc_pref_index,a$ballotcondition)),row.names=F)
summary(lm(inc_pref_index ~ ballotcondition, data=a)) # beta=0.285, p=0.019

t.test(a$inc_pref_index[a$ballotcondition=="on"],a$inc_pref_index[a$ballotcondition=="off"])
# off-cycle condition respondents voted for 1.38 incumbents, while on-cycle respondents voted for incumbent in 1.66 races
crosstab(a$inc_pref_index>0,a$ballotcondition,prop.c=T)


# placebo race with no incumbent candidate (irrigation board):
crosstab(a$irrigation_eng_comb,a$ballotcondition,prop.c=T)

summary(lm(irrigation_eng_comb ~ ballotcondition, data=a[a$scr_pass==2,])) # beta=-0.02, p=0.58

# Mayoral incumbency preference by political knowledge:
summary(lm(mayor_inc_comb ~ polinfo + ballotcondition, data=a)) # ballot cond beta=0.06, p=0.264
summary(lm(mayor_inc_comb ~ polinfo, data=a)) # beta=0.14, p=0.124

# Overall incumbency preference by political knowledge:
t.test(a$inc_pref_index[a$polinfo>0.6],a$inc_pref_index[a$polinfo<=0.6])
summary(lm(inc_pref_index ~ polinfo + ballotcondition, data=a)) # ballot still has effect (0.39) but no effect of knowledge
summary(lm(inc_pref_index ~ polinfo, data=a)) # beta=0.11, p=0.657
summary(lm(inc_pref_index ~ (polinfo>0.6) + ballotcondition, data=a)) # ballot still has effect (0.38) but neg insig effect of knowledge
summary(lm(inc_pref_index ~ (polinfo>0.6), data=a)) # beta=-0.04, p=0.748

# Overall incumbency preference by education:
summary(lm(inc_pref_index ~ (educ>4) + ballotcondition, data=a)) # ballot and educ sig positive effects
summary(lm(inc_pref_index ~ educ>4, data=a)) # beta=0.35, p=0.004





